const API_URL = 'https://api.openai.com/v1/engines/davinci-codex/completions';
 function getAnswer(question) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: API_URL,
      method: 'POST',
      header: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer xxxxxx', // 替换为你的 OpenAI API Key
      },
      data: {
        'prompt': question,
        'max_tokens': 256,
        'temperature': 0.7,
        'n': 1,
        'stop': '\n',
      },
      success: function(res) {
        if (res.statusCode === 200) {
          let answer = res.data.choices[0].text.trim();
          resolve(answer);
        } else {
          reject(new Error('请求失败，错误码：' + res.statusCode));
        }
      },
      fail: function(err) {
        console.log(err);
        reject(new Error('请求失败'));
      },
    });
  });
}
 module.exports = {
  getAnswer: getAnswer,
};